<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        //【3】【提取】
        var regex11 = /^(\d{4}\D(\d{2})\D(\d{2})$)/;
        var string11 = '2017-06-26';
        //【3-1】string对象的match（）方法，返回数组【实战中，该方法最常用】
        console.log(string11.match(regex11));
        //["2017-06-26", "2017-06-26", "06", "26", index: 0, input: "2017-06-26"]
        //【3-2】string对象的search（）方法，通过参数获取其中的数据。
        console.log(string11.search(regex11)); //0
        console.log(RegExp.$1); //2017-06-26
        console.log(RegExp.$2); //06
        console.log(RegExp.$3); //26
        //【3-3】string对象的replace（）方法，通过回调函数提取数据
        var res = [];
        string11.replace(regex11, function(match, year, month, day) {
            res.push(match, year, month, day);
        });
        console.log(res); // ["2017-06-26", "2017-06-26", "06", "26"]
        //【3-4】regex对象的exec（）方法，返回数组
        console.log(regex11.exec(string11));
        //["2017-06-26", "2017-06-26", "06", "26", index: 0, input: "2017-06-26"]
        //【3-5】regex对象的test（）方法，通过后续的参数来提取数据。
        regex11.test(string11);
        console.log(RegExp.$1); //2017-06-26
    </script>
</body>

</html>